package com.catchman.demo;


import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;


@SpringBootApplication
public class DemoApplication implements ApplicationRunner {
    private static final Logger logger = LoggerFactory.getLogger(DemoApplication.class);


    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        //-------------简单数据源，非连接池
//        // SimpleDataSource只是DriverManager.getConnection的简单包装，本身并不支持池化功能，此类特别适合少量数据库连接的操作。
//        DataSource ds = new SimpleDataSource("jdbc:h2:file:./testable;DB_CLOSE_ON_EXIT=FALSE", "sa", "");
//        Connection conn = ds.getConnection();
//
//        // 执行非查询语句，返回自增的键，如果有多个自增键，只返回第一个
//        int count = SqlExecutor.execute(conn, "insert into user values(?,?)", 5L, "husxin");
//        logger.info(String.valueOf(count));
//        List<Entity> entityList = SqlExecutor.query(conn, "select * from user where USE_ID = ?", new EntityListHandler(), 5L);
//        logger.info("{}", entityList);
//


//      读取默认配置文件 config/db.setting 支持连接池
        List<Entity> list = Db.use().findAll("USER"); //好像区分大小写
        System.out.println(list);


        System.err.println("ceshirizhi");
        logger.error("测试日志！");

    }


}
